<?php

class IndexController extends Site_Controller_Action
{
    
    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        Zend_Loader::loadClass('datetools','library');
        
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        
        $obj = $db->fetchRow('SELECT SQL_CACHE * FROM TEXTOHOME WHERE TXH_STA = 1');
        $this->view->texto = $obj;
        
        
        $obj = $db->fetchAll('SELECT SQL_CACHE * FROM BLOG WHERE BLO_STA = 1 ORDER BY BLO_DAT DESC LIMIT 2'); // , BLO_HOR DESC
        $this->view->blog = $obj;
        
    }
    public function calendarioAction(){
        $this->_helper->layout->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender();
        
        Zend_Loader::loadClass('calendario','library');
        
        $count = 0;
        $script = '';
        
        $data = explode('-',$this->_getParam('data'));
        $mes = $data[1];
        $ano = $data[0];
        
        $html1 = Calendario::buscaCalendario($ano,$mes);
        
        $html2 = '';
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $cal = $db->fetchAll('SELECT SQL_CACHE CAL_NOM, DAY(CAL_DAT) as DIA, MONTH(CAL_DAT) as MES FROM CALENDARIO WHERE YEAR(CAL_DAT) = "'.$ano.'" and MONTH(CAL_DAT) = "'.$mes.'" and CAL_STA = 1 ORDER BY CAL_DAT ASC, CAL_NOM ASC LIMIT 18');
        foreach($cal as $c){
            $count++;
            if( $c['DIA'] < 10) $c['DIA'] = "0".$c['DIA'];
            $html2 .= '<li><strong>'.$c['DIA'].'/'.$c['MES'].'</strong> | '.$c['CAL_NOM'].'</li>';
        }
        
        if($count > 9) $script = '<script>$(function(){ $(".lista_calendario").css("width","460px"); });</script>';
        else $script = '<script>$(function(){ $(".lista_calendario").css("width","230px"); });</script>';
        
        echo json_encode(array('html1'=>$html1,'html2'=>$html2,'script'=>$script));
    }
}

